<div>
  <div class="main-title">
    <h2>权限管理</h2>
  </div>
  <div class="main-section form-inline">
    <a href="{:url('edit', ['admin_role_id' => $admin_role_id])}" class="btn btn-success">+ 增加</a>
    <select class="j-select form-control" style="width: 120px; margin-left: 2px;">
      <option value="{:url('', ['admin_role_id' => 0])}">未选择</option>
      {foreach $roles as $v}
      <option value="{:url('', ['admin_role_id' => $v.id])}" {if $admin_role_id==$v.id}selected{/if}>
        {$v.name}
      </option>
      {/foreach}
    </select>
  </div>
  <div class="main-section">
    <table class="table table-striped table-bordered table-hover">
      <thead>
        <tr>
          <th>角色</th>
          <th>允许的控制器</th>
          <th>允许的操作</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        {if $role}
        {foreach $role.adminPermission as $v}
        <tr>
          <td>
            <a href="{:url('admin.role/edit', ['id' => $role.id])}" class="j-menu-to">{$role.name}</a>
          </td>
          <td>{$v.controller}</td>
          <td>{$v.action}</td>
          <td>
            <a href="{:url('edit', ['id' => $v.id])}" style="margin-right: 5px;">编辑</a>
            <a href="{:url('delete', ['id' => $v.id])}" class="j-del text-danger">删除</a>
          </td>
        </tr>
        {/foreach}
        {/if}
        {if empty($role) || $role->adminPermission->isEmpty()}
        <tr>
          <td colspan="4" class="text-center">列表为空</td>
        </tr>
        {/if}
      </tbody>
    </table>
  </div>
</div>

<script>
  $('.j-del').click(function() {
    if(confirm('您确定要删除此项？')) {
      main.ajaxPost($(this).attr('href'), function() {
        main.contentRefresh();
      });
    }
    return false;
  });
  $('.j-menu-to').click(function() {
    main.content($(this).attr('href'), function() {
      main.menuActive('admin.role');
    });
    return false;
  });
  $('.j-select').change(function() {
    main.content($(this).val());
  });
</script>